package com.loan.repository;

import com.loan.entity.Channel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by huxudong on 17/7/1.
 */
public interface ChannelRepository extends JpaRepository<Channel,Long> {

    public List<Channel> findByFlagOrderBySort(Integer flag);

    public List<Channel> findByFlagAndIsHotOrderBySort(Integer flag ,Integer isHot);

    public List<Channel> findTop4ByFlagAndIsHotOrderBySort(Integer flag ,Integer isHot);

     @Modifying
     @Transactional
     @Query("UPDATE Channel c SET c.isHot = ?1 where c.id = ?2")
     public void updateHot(Integer isHot , Long id);

}
